<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('股东/合伙人') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('名称')" prop="partnerName">
        <el-input
          v-model="queryParams.partnerName"
          :placeholder="$t('名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('合伙人类型')" prop="partnerType">
        <el-select v-model="queryParams.partnerType" :placeholder="$t('合伙人类型')" clearable>
          <el-option
            v-for="dict in partnerTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['gp:partner:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="gpPartnerList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('名称')" align="center" prop="partnerName" min-width="180" />
      <el-table-column :label="$t('合伙人类型')" align="center" prop="partnerType" min-width="120" :formatter="partnerTypeFormat" />
      <el-table-column :label="$t('是否实际控股人')" align="center" prop="whetherControl" min-width="140" :formatter="whetherControlFormat" />
      <el-table-column :label="$t('认缴出资额') + $t('金额单位')" align="center" prop="subscribeAmount" min-width="140">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.subscribeAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实缴出资额') + $t('金额单位')" align="center" prop="paidInAmount" min-width="140">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.paidInAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否离开')" align="center" prop="whetherLeave" min-width="140" :formatter="whetherLeaveFormat" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['gp:partner:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}
          </el-button>
          <el-button
            v-hasPermi="['gp:partner:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改内部基金管理人-股东/合伙人对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <gpPartnerForm ref="gpPartnerForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listGpPartner, delGpPartner, exportGpPartner } from '@/api/fund/gp/partner/gpPartner'
import gpPartnerForm from './gpPartnerForm.vue'

export default {
  components: {
    gpPartnerForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 内部基金管理人-股东/合伙人表格数据
      gpPartnerList: [],
      // 弹出层标题
      title: '股东/合伙人',
      // 是否显示弹出层
      formOpen: false,
      // 合伙人类型字典
      partnerTypeOptions: [],
      // 查询参数
      queryParams: {
        gpId: this.$route.query.gpId,
        partnerName: undefined,
        partnerType: undefined,
        whetherControl: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 是否字典
      yesNoOptions: []
    }
  },
  created() {
    this.getList()
    this.getDicts('gp_partner_type').then(response => {
      this.partnerTypeOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.yesNoOptions = response.data
    })
  },
  methods: {
    /** 查询内部基金管理人-股东/合伙人列表 */
    getList() {
      this.loading = true
      listGpPartner(this.queryParams).then(response => {
        this.gpPartnerList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 合伙人类型字典翻译
    partnerTypeFormat(row) {
      return this.selectDictLabel(this.partnerTypeOptions, row.partnerType)
    },
    // 是否实际控股人字典翻译
    whetherControlFormat(row) {
      return this.selectDictLabel(this.yesNoOptions, row.whetherControl)
    },
    // 是否离开字典翻译
    whetherLeaveFormat(row) {
      return this.selectDictLabel(this.yesNoOptions, row.whetherLeave)
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        gpId: this.$route.query.gpId,
        partnerName: undefined,
        partnerType: undefined,
        whetherControl: undefined,
        holderDate: undefined,
        whetherLicense: undefined,
        subscribeAmount: undefined,
        subscribeRate: undefined,
        paidInAmount: undefined,
        paidInRate: undefined,
        whetherLeave: undefined,
        leaveDate: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.gpPartnerForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.gpPartnerForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delGpPartner(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return exportGpPartner(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(function() {
      })
    }
  }
}
</script>
